package mani.threads;


public class PrintJob {
	private int number;
	boolean turn = false;
	
	public PrintJob() {
		number =1;
	}
	
	public synchronized void printEven(){
		if(!turn){
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		System.out.println(number);
		number+=1;
		turn = false;
		notify();		
	}
	
	public synchronized void printOdd(){
		if(turn){
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		System.out.println(number);
		number+=1;
		turn = true;
		notify();		
	}

}
